package cn.wolfcode.luowowo.acticle.service.impl;


import cn.wolfcode.luowowo.acticle.domain.StrategyTag;
import cn.wolfcode.luowowo.acticle.mapper.StrategyTagMapper;
import cn.wolfcode.luowowo.acticle.service.IStrategyTagService;
import cn.wolfcode.luowowo.common.exception.DisplayableException;
import cn.wolfcode.luowowo.common.query.QueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@Transactional
@Service
public class StrategyTagServiceImpl implements IStrategyTagService {
    @Autowired
    private StrategyTagMapper strategyTagMapper;

    @Override
    public PageInfo query(QueryObject qo) {

        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());

        return new PageInfo(strategyTagMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(StrategyTag strategyTag) throws DisplayableException {
        if(strategyTag.getId() == null){
            strategyTagMapper.insert(strategyTag);
        }else{
            strategyTagMapper.updateByPrimaryKey(strategyTag);
        }
    }

    @Override
    public void delete(Long id) throws DisplayableException {
        strategyTagMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<StrategyTag> list() {
        return strategyTagMapper.selectAll();
    }

    @Override
    public List<String> getTagsBySDetailId(Long id) {
        return strategyTagMapper.selectTagsByDetailId(id);
    }
}
